import { createI18n } from 'vue-i18n'
import elementEnLocale from 'element-plus/es/locale/lang/en' // english lang
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn'// chinese lang
import enLocale from './locales/en.json'
import zhLocale from './locales/zh.json'
import Cookies from 'js-cookie'

const messages = {
  en: {
    ...enLocale,
    ...elementEnLocale
  },
  zh: {
    ...zhLocale,
    ...elementZhLocale
  }
}

export default createI18n({
  legacy: false,
  globalInjection: true,
  locale: process.env.VUE_APP_I18N_LOCALE || Cookies.get('language') || 'en',
  fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
  messages
})
